package 程序员面试金典;

import org.junit.Test;

import java.util.LinkedList;
import java.util.Queue;

//动物收容站
public class AnimalShelf {

    Queue<int[]> cat;
    Queue<int[]> dog;
    public AnimalShelf() {
        cat=new LinkedList<>();
        dog=new LinkedList<>();
    }

    public void enqueue(int[] animal) {
         if (animal[1]==0)
             cat.offer(animal);
         else
             dog.offer(animal);
    }

    public int[] dequeueAny() {
        int[] cat1 = cat.peek();
        int[] dog1 = dog.peek();
//        if (cat1==null && dog1==null)
//            return new int[]{-1,-1};
        if (cat1==null){
            dog.poll();
            return dog1;
        }
        if (dog1==null){
            cat.poll();
            return cat1;
        }
        if (cat1[0]<dog1[0]) {
            cat.poll();
            return cat1;
        }
        if (cat1[0]>dog1[0]) {
            dog.poll();
            return dog1;
        }
        return new int[]{-1,-1};
    }

    public int[] dequeueDog() {
       if (dog.size()!=0)
           return dog.poll();
       return new int[]{-1,-1};
    }

    public int[] dequeueCat() {
        if (cat.size()!=0)
            return cat.poll();
        return new int[]{-1,-1};
    }

    @Test
    public void test(){
        Queue queue=new LinkedList();
        System.out.println(queue!=null);
        System.out.println(queue.peek());
    }
}
